import request from "@/utils/request";
import { defineStore } from "pinia";
import {
  IApiRes,
  bannerType,
  INewGoods,
  HotType,
  Brand,
  HomeProduct,
  Special,
} from "@/types/data";
export default defineStore("home", {
  state() {
    return {
      bannerList: [] as bannerType[],
      newGoodsList: [] as INewGoods[],
      HotGoodsList: [] as HotType[],
      BrandList: [] as Brand[],
      productList: [] as HomeProduct[],
      specialList: [] as Special[],
    };
  },
  actions: {
    // 轮播图
    async getBannerList() {
      const res = await request.get<IApiRes<bannerType[]>>("/home/banner");
      this.bannerList = res.data.result;
    },
    // 新鲜
    async getNewGoodsList() {
      const res = await request.get<IApiRes<INewGoods[]>>("/home/new");
      this.newGoodsList = res.data.result;
    },
    // 人气
    async getHotList() {
      const res = await request.get<IApiRes<HotType[]>>("/home/hot");
      this.HotGoodsList = res.data.result;
    },
    // 热门
    async getBrandList() {
      const res = await request.get<IApiRes<Brand[]>>("/home/brand");
      this.BrandList = res.data.result;
    },
    // 首页
    async getproductList() {
      const res = await request.get<IApiRes<HomeProduct[]>>("/home/goods");
      this.productList = res.data.result;
    },
    // 最新
    async getspecialList() {
      const res = await request.get<IApiRes<Special[]>>("/home/special");
      this.specialList = res.data.result;
    },
  },
  getters: {},
});
